home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 1 / PCU0103CD1.iso / entertn / demos / files / aomtrial.exe / AOM / AI / SCN25P3.XS < prev    next >
Encoding:
Text File  |  2002-09-06  |  9.6 KB  |  277 lines

  1. //==============================================================================
  2. // Scn25p3: AI Scenario Script for scenario 25 player 3
  3. //==============================================================================
  4. /*
  5.    AI owner:  Dave Leary
  6.    Scenario owner: Joe "The Golem" Gillum
  7.  
  8.    Overview: Very basic AI script that trains giants and einherjar.
  9.     
  10.    This AI takes the majority of generated units and sends them to attack the HP,
  11.     leaving a few behind at the gather point for town defense.  It relies on P2 to
  12.     do its scouting for it.  Population is provided by houses at the back of the
  13.     map.
  14. */
  15. //==============================================================================
  16. include "scn lib.xs";
  17.  
  18. //==============================================================================
  19. // Set Town Location
  20. //==============================================================================
  21. void setTownLocation(void)
  22. {
  23.    //Look for the "Town Location" marker.
  24.    kbSetTownLocation(kbGetBlockPosition("8086"));
  25. }
  26.  
  27. //==============================================================================
  28. // miscStartup
  29. //==============================================================================
  30. void miscStartup(void)
  31. {
  32.     // Difficulty Level check.
  33.     int difflevel=-1;        
  34.     difflevel=aiGetWorldDifficulty();
  35.  
  36.    //Startup message(s).
  37.    aiEcho("");
  38.    aiEcho("");
  39.    aiEcho("Scn25P3 AI Start, filename='"+cFilename+"'.");
  40.     aiEcho("Difficulty Level="+difflevel+".");
  41.    //Spit out the map size.
  42.    aiEcho("  Map size is ("+kbGetMapXSize()+", "+kbGetMapZSize()+").");
  43.    //Cheat like a bastard.  Once only, though.
  44.    kbLookAtAllUnitsOnMap();
  45.    //Calculate some areas.
  46.    kbAreaCalculate(1200.0);
  47.    //Set our town location.
  48.    setTownLocation();
  49.     //Reset random seeds
  50.     aiRandSetSeed();
  51.  
  52.     //Allocate all resources to the root escrow by setting percentage of military/economy to 0.
  53.     kbEscrowSetPercentage( cEconomyEscrowID, cAllResources, 0.0 );
  54.     kbEscrowSetPercentage( cMilitaryEscrowID, cAllResources, 0.0 );
  55.  
  56.    //Allocate all resources
  57.    kbEscrowAllocateCurrentResources();
  58. }
  59.  
  60. //==============================================================================
  61. //==============================================================================
  62. // Attack stuff.
  63. //==============================================================================
  64. //==============================================================================
  65. // Shared variables.
  66. int numberAttacks=0;
  67. int attackPlayerID=-1;
  68.  
  69. // Attack vars.
  70. int attackPlanID=-1;
  71.  
  72. // Saved maintain plan IDs
  73. int maintainPlan1ID=-1;
  74. int maintainPlan2ID=-1;
  75.  
  76. // Unit types
  77. int attackerUnitTypeID1=cUnitTypeFrostGiant;
  78. int attackerUnitTypeID2=cUnitTypeEinheriar;
  79.  
  80. //==============================================================================
  81. // initAttack: Creates attack routes, etc.
  82. //==============================================================================
  83. void initAttack(int playerID=-1)
  84. {
  85.    //Destroy all previous attacks (if this isn't the player we're already attacking.)
  86.    if (playerID != attackPlayerID)
  87.    {
  88.       //Reset the attack player ID.
  89.       attackPlayerID=-1;
  90.       //Destroy any previous attack plan.
  91.       aiPlanDestroy(attackPlanID);
  92.       attackPlanID=-1;
  93.  
  94.       //Reset the number of attacks.
  95.       numberAttacks=0;
  96.    }
  97.  
  98.    //Save the player to attack.
  99.    attackPlayerID=playerID;
  100. }
  101.  
  102. //==============================================================================
  103. // setupAttack
  104. //==============================================================================
  105. bool setupAttack(int playerID=-1)
  106. {
  107.     // Difficulty Level check.
  108.     int difflevel=-1;        
  109.     difflevel=aiGetWorldDifficulty();
  110.  
  111.     //Info.
  112.     aiEcho("Attacking Player "+playerID+".");
  113.  
  114.    //If the player to attack doesn't match, init the attack.
  115.    if (attackPlayerID != playerID)
  116.    {
  117.       initAttack(playerID);
  118.       if (attackPlayerID < 0)
  119.          return(false);
  120.    }
  121.  
  122.    //Create an attack plan.
  123.    int newAttackPlanID=aiPlanCreate("Attack Player"+attackPlayerID+" Attempt"+numberAttacks, cPlanAttack);
  124.    if (newAttackPlanID < 0)
  125.       return(false);
  126.  
  127.    //Target player (required).  This must work.
  128.    if (aiPlanSetVariableInt(newAttackPlanID, cAttackPlanPlayerID, 0, attackPlayerID) == false)
  129.       return(false);
  130.  
  131.    //Gather point.
  132.     vector gatherPoint=kbGetBlockPosition("8086");
  133.  
  134.     //Set the target type.  This must work.
  135.    if (aiPlanSetNumberVariableValues(newAttackPlanID, cAttackPlanTargetTypeID, 2, true) == false)
  136.       return(false);
  137.  
  138.    aiPlanSetNumberVariableValues(newAttackPlanID, cAttackPlanTargetTypeID, 2, true);
  139.     
  140.     //Unit types to attack.
  141.    aiPlanSetVariableInt(newAttackPlanID, cAttackPlanTargetTypeID, 0, cUnitTypeUnit);
  142.     aiPlanSetVariableInt(newAttackPlanID, cAttackPlanTargetTypeID, 1, cUnitTypeBuilding);
  143.  
  144.    //Set the gather point and gather point distance.
  145.    aiPlanSetVariableVector(newAttackPlanID, cAttackPlanGatherPoint, 0, gatherPoint);
  146.    aiPlanSetVariableFloat(newAttackPlanID, cAttackPlanGatherDistance, 0, 25.0);
  147.  
  148.     //Add the unit types to the plan - giants...
  149.     if ( difflevel < 2 )
  150.     {
  151.         aiPlanAddUnitType(newAttackPlanID, attackerUnitTypeID1, 0, 1, 1);
  152.     }
  153.     else if ( difflevel == 2 )
  154.     {
  155.         aiPlanAddUnitType(newAttackPlanID, attackerUnitTypeID1, 0, 2, 2);
  156.     }
  157.     else
  158.     {
  159.         aiPlanAddUnitType(newAttackPlanID, attackerUnitTypeID1, 0, 3, 3);
  160.     }
  161.     //...and einhariwhatsises...
  162.     // aiPlanAddUnitType(newAttackPlanID, attackerUnitTypeID2, 2, 4, 4);
  163.     
  164.    //Set the initial position.
  165.    aiPlanSetInitialPosition(newAttackPlanID, gatherPoint);
  166.  
  167.    //Plan requires all need units to work (can be false).
  168.    aiPlanSetRequiresAllNeedUnits(newAttackPlanID, true);
  169.    
  170.     //Activate the plan.
  171.    aiPlanSetActive(newAttackPlanID);
  172.  
  173.    //Now, save the attack plan ID appropriately.
  174.    aiPlanSetOrphan(attackPlanID, true);
  175.    attackPlanID=newAttackPlanID;
  176.  
  177.    //Increment our overall number of attacks.
  178.    numberAttacks++;
  179. }
  180.  
  181. //==============================================================================
  182. // Attack Generator - Send dudes now!  Or, well, soon.  Every 150 seconds.
  183. //==============================================================================
  184. rule attackGenerator
  185.    minInterval 270
  186.    inactive
  187.    group AttackRules
  188. {
  189.    //See how many "idle" attack plans we have.  Don't create any more if we have
  190.    //idle plans.
  191.    int numberIdleAttackPlans=aiGetNumberIdlePlans(cPlanAttack);
  192.  
  193.    if (numberIdleAttackPlans > 0)
  194.       return;
  195.  
  196.    //If we have enough unassigned military units, create a new attack plan.
  197.    int numberAvailableUnits=aiNumberUnassignedUnits(attackerUnitTypeID1);
  198.    aiEcho("There are "+numberAvailableUnits+" giants available for a new attack.");
  199.    
  200.     if (numberAvailableUnits >= 1)
  201.         setupAttack(1);
  202. }
  203.  
  204. //==============================================================================
  205. // Attack Enabler
  206. //==============================================================================
  207. rule attackEnabler
  208.    minInterval 500
  209.    active
  210.    group AttackRules
  211. {
  212.     aiEcho("*** ATTACKS ENABLED - P3 ***");
  213.     xsEnableRule("attackGenerator");
  214.     xsDisableSelf();
  215. }
  216.  
  217. //==============================================================================
  218. // Favor cheat 
  219. //==============================================================================
  220. rule favorCheat
  221.    minInterval 60
  222.    active
  223.    group AttackRules
  224. {
  225.     // Cheat for favor.  It's tough to be Norse.
  226.     aiResourceCheat( 3, cResourceFavor, 100.0 );
  227. }
  228.  
  229. //==============================================================================
  230. // MAIN.
  231. //==============================================================================
  232. void main(void)
  233. {
  234.     vector gatherPoint=kbGetBlockPosition("8086");
  235.     
  236.     // Locations for spawning fun
  237.     miscStartup();
  238.  
  239.    //Maintain giants - three total, one that gets sent on easy/moderate, more that get sent
  240.     // on other levels.
  241.    maintainPlan1ID=aiPlanCreate("Maintain "+kbGetProtoUnitName(attackerUnitTypeID1), cPlanTrain);
  242.    if (maintainPlan1ID >= 0)
  243.    {
  244.         //Must set the type of unit to train.
  245.       aiPlanSetVariableInt(maintainPlan1ID, cTrainPlanUnitType, 0, attackerUnitTypeID1);
  246.       //You can limit the number of units that are ever trained by this plan with this call.
  247.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanNumberToTrain, 0, 25);
  248.       //Set the number of units to maintain in the world at one time.
  249.       aiPlanSetVariableInt(maintainPlan1ID, cTrainPlanNumberToMaintain, 0, 3);
  250.       //Don't train units too fast
  251.       aiPlanSetVariableInt(maintainPlan1ID, cTrainPlanFrequency, 0, 90);
  252.       //Set a gather point.
  253.       aiPlanSetVariableVector(maintainPlan1ID, cTrainPlanGatherPoint, 0, gatherPoint);
  254.       //Activate the plan.
  255.       aiPlanSetActive(maintainPlan1ID);
  256.    }
  257.  
  258.     /*
  259.     //Maintain einherjar - six total, four get sent at a time.
  260.    maintainPlan2ID=aiPlanCreate("Maintain 6 "+kbGetProtoUnitName(attackerUnitTypeID2), cPlanTrain);
  261.    if (maintainPlan2ID >= 0)
  262.    {
  263.         //Must set the type of unit to train.
  264.       aiPlanSetVariableInt(maintainPlan2ID, cTrainPlanUnitType, 0, attackerUnitTypeID2);
  265.       //You can limit the number of units that are ever trained by this plan with this call.
  266.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanNumberToTrain, 0, 25);
  267.       //Set the number of units to maintain in the world at one time.
  268.       aiPlanSetVariableInt(maintainPlan2ID, cTrainPlanNumberToMaintain, 0, 6);
  269.       //Don't train units too fast
  270.       aiPlanSetVariableInt(maintainPlan2ID, cTrainPlanFrequency, 0, 20);
  271.       //Set a gather point.
  272.       aiPlanSetVariableVector(maintainPlan2ID, cTrainPlanGatherPoint, 0, gatherPoint);
  273.       //Activate the plan.
  274.       aiPlanSetActive(maintainPlan2ID);
  275.    }
  276.     */
  277. }